package com.mldong.modules.cms.controller;

import com.mldong.auth.Perm;
import com.mldong.base.CommonPage;
import com.mldong.base.CommonResult;
import com.mldong.base.IdParam;
import com.mldong.base.IdsParam;
import com.mldong.modules.cms.dto.ViewClickPageParam;
import com.mldong.modules.cms.dto.ViewClickParam;
import com.mldong.modules.cms.service.ViewClickService;
import com.mldong.modules.cms.vo.ViewClickVO;
import com.mldong.validation.Groups;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
    * 页面访问量 前端控制器
    * </p>
*
* @author mldong
* @since 2022-10-23
*/
@RestController
@Api(tags = "页面访问量管理")
@RequiredArgsConstructor
public class ViewClickController {
    private final ViewClickService viewClickService;
    /**
     * 添加页面访问量
     * @param param
     * @return
     */
    @PostMapping("/cms/viewClick/save")
    @ApiOperation(value = "添加页面访问量")
    @Perm
    public CommonResult<?> save(@RequestBody @Validated({Groups.Save.class}) ViewClickParam param) {
        viewClickService.save(param);
        return CommonResult.ok();
    }
    /**
     * 删除页面访问量
     * @param param
     * @return
     */
    @PostMapping("/cms/viewClick/remove")
    @ApiOperation(value = "删除页面访问量")
    @Perm
    public CommonResult<?> remove(@RequestBody IdsParam param) {
        viewClickService.removeBatchByIds(param.getIds());
        return CommonResult.ok();
    }
    /**
     * 修改页面访问量
     * @param param
     * @return
     */
    @PostMapping("/cms/viewClick/update")
    @ApiOperation(value = "修改页面访问量")
    @Perm
    public CommonResult<?> update(@RequestBody @Validated({Groups.Update.class}) ViewClickParam param) {
        viewClickService.update(param);
        return CommonResult.ok();
    }
    /**
     * 查询单个页面访问量
     * @param param
     * @return
     */
    @PostMapping("/cms/viewClick/detail")
    @ApiOperation(value = "查询单个页面访问量")
    @Perm
    public CommonResult<ViewClickVO> detail(@RequestBody IdParam param) {
        ViewClickVO viewClick = viewClickService.findById(param.getId());
        return CommonResult.data(viewClick);
    }
    /**
     *分页查询页面访问量列表
     * @param param
     * @return
     */
    @PostMapping("/cms/viewClick/page")
    @ApiOperation(value = "分页查询页面访问量列表")
    @Perm
    public CommonResult<CommonPage<ViewClickVO>> page(@RequestBody ViewClickPageParam param) {
        return CommonResult.data(viewClickService.page(param));
    }
}
